// pages/driver_list/driver_list.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading:true,
    // 订单状态
    status: 0,
    page:1,//页码，
    totalpage:1,//总页数
  },
  // 切换tab
  tab: function (event) {

    var that = this;
    var status = event.currentTarget.dataset.status;

    that.setData({
      status: status,
      page:1,
      totalpage:1
    });
    that.getData();

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getData();
  },
  //获取司机列表
  getData:function(res){
    var that = this;
    if (that.data.page <= that.data.totalpage){
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api + '/wx_log_test/sys/approve',
          data: {
            token: session,
            page: that.data.page,
            perpage: 10,
            status: that.data.status
          },
          success: function (res) {
            console.log(res);
            var res = res.data;
            if (res.msg == "OK") {
              var data = res.data;
              if (data.content.length == 0) {
                that.setData({
                  loading: false,
                  loadtips: '暂无相关数据',
                  content:[]
                })
              } else {
                that.setData({
                  loading: false,
                  totalpage: data.totalPages,
                  content: data.content,
                  page:that.data.page+1,
                  loadtips:''
                })
              }
            } else {
              that.setData({
                loading: false,
                loadtips: res.msg
              })
            }
          },
          fail: function (res) {
            that.setData({
              loading: false,
              loadtips: '接口请求失败'
            })
          }
        })
      })
    }else{
      console.log("jdljflsdjfl");
    }
    
  },
  onShow: function () {
    this.setData({
      loading: true,
      // 订单状态
      status: 0,
      page: 1,//页码，
      totalpage: 1,//总页数
    })
    this.getData();
  },
  onShareAppMessage: function () {
  
  },
  call: function (res) {
    wx.makePhoneCall({
      phoneNumber: res.currentTarget.dataset.num //仅为示例，并非真实的电话号码
    })
  },
})